<template>
<div>
    <h2>欢迎登录</h2>
    用户名：<input type="text" v-model:value="username"  /> <br />
	密码：<input type="text" v-model:value="password"  /> <br />
	验证码：<input type="text" v-model:value="userValidateCode" /><img src="http://localhost:8080/redis/user/getCode"  @click="updateCode()" id="m1" /><br />
	<button type="button" @click="validate()">登录</button><br />
    {{msg}}

</div>

</template>

<script>
export default {
  
    data(){
        return{
            validateCode:"",
            username:"",
            password:"",
            userValidateCode:"",
            msg:"",

        }
    },
    methods:{
        updateCode(){
            console.log("666");
            $("#m1").attr("src","http://localhost:8080/redis/user/getCode?a=" + Math.random());
        },
     
        validate(){
            let config = {
                headers:{
                    "Content-Type":"text/plain"
                }
            }
            this.$axios.post("user/validateCode",this.userValidateCode,config).then((response) => {
                let ResultVO = response.data;
                let respCode = ResultVO.code;
                

                if(respCode==205){
                    console.log("205");
                    this.login();
                    return;
                }
                this.msg=ResultVO.msg;
            });

        },
        login(){
            let user = new Object();
            user.username = this.username;
            user.password = this.password;
            this.$axios.post("user/login",user).then((response) => {
                let ResultVO = response.data;
                
                this.msg = ResultVO.msg;
                
            });


        }

    }

}
</script>

<style>
#m1{
    width:50px;
    
}

</style>